﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MainEntrySection.xaml.cs" company="Mar3ek">
//   This code is licensed under the Mozilla Public License 2.0.
//   You can find the full license text at the following address:
//   https://winkee.codeplex.com/license
// </copyright>
// <summary>
//   Defines the MainEntrySection type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace WinKee.Controls
{
    using Windows.UI.Xaml;

    /// <summary>
    /// The control for displaying main entry data.
    /// </summary>
    public sealed partial class MainEntrySection
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MainEntrySection"/> class.
        /// </summary>
        public MainEntrySection()
        {
            this.InitializeComponent();

            VisualStateManager.GoToState(this, "PasswordState", true);
            Instance = this;
        }

        /// <summary>
        /// Gets the current instance.
        /// </summary>
        public static MainEntrySection Instance { get; private set; }

        /// <summary>
        /// Selects the password.
        /// </summary>
        internal void SelectPassword()
        {
            this.DisplayPasswordCheckBox.IsChecked = true;
            this.PasswordTextBox.Focus(FocusState.Pointer);
            this.PasswordTextBox.SelectAll();
        }

        /// <summary>
        /// Selects the username.
        /// </summary>
        internal void SelectUsername()
        {
            this.UsernameTextBox.Focus(FocusState.Pointer);
            this.UsernameTextBox.SelectAll();
        }

        /// <summary>
        /// The toggle button_ on checked.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void DisplayPasswordCheckBoxOnChecked(object sender, RoutedEventArgs e)
        {
            VisualStateManager.GoToState(this, "TextboxState", true);
        }

        private void DisplayPasswordCheckBoxOnUnchecked(object sender, RoutedEventArgs e)
        {
            VisualStateManager.GoToState(this, "PasswordState", true);
        }
    }
}
